<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <el-row>
    <el-button type="primary" @click="logout">logout</el-button>
  </el-row>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: sessionStorage.getItem('token')
    }
  },
  methods: {
    logout() {
      var vm = this;
      this.disablebtn = true;
      this.loginText = "退出中";
      this.$axios
        .get("logout")
        .then(res => {
          if (res.data.code == 201) {
            sessionStorage.removeItem("token"); 
            vm.$router.replace("/login");
          } else {
            vm.disablebtn = false;

            vm.$alert(res.data.msg, '错误', {
              confirmButtonText: '确定'
            });
           

          }
        })
        .catch(function(err) {
    
          console.log(err);
        });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
